@include "misc.awk"
@include "readerHeadRow.awk"

function reader(   _local,_t) {
    OFS=FS=","
    args("in=/dev/stdin",Opt,_local)
    lines(Opt["in"],_t)
}
function classp(x)     { return x ~ /!/ }
function ignorep(x)    { return x ~ /\?/ }
function nump(x)       { return x ~ /\$/ }
function hatep(x)      { return x ~ /</ }
function asRow(r,   c) { 
    delete r; 
    for(c=1;c<=NF;c++) r[c]=$c 
}
function lines(f,t,_act,    r,n) { 
    _act = the(_act,"line"); 
    while ((getline < f) > 0) 
        if (goodLine()) { 
            asRow(r)
            @_act(t,r, ++n) 
        }}
function goodLine() { 
    sub(/#.*/,"")
    gsub(/[ \t]/,"")
    return $0 !~ /^[ \t]*$/ 
}
function line(t,r,n) {
    n==1 ? header(t,r) : row(t,r)
}
function rowPrint(r,_sep) {
    print row2String(r,_sep)
}
function row2String(r,_sep,     c,out) {
    _sep = the(_sep,",")
    out=r[1]
    for(c=2;c<=length(r);c++) 
        out = out _sep r[c]
    return out
}
